// 订单相关的API函数
import request from '@/utils/request'
/**
 * 创建订单结算信息
 */
export const createOrderInfo = () => {
  return request('/member/order/pre', 'get')
}
/**
 * 添加收货地址
 * @param {object} form
 */
export const addAddress = (form) => {
  return request('/member/address', 'post', form)
}
/**
 * 编辑收货地址
 * @param {object} address
 */
export const editAddress = (form) => {
  return request(`/member/address/${form.id}`, 'put', form)
}
/**
 * 获取收货地址列表
 * @param {object} form
 */
export const findAddressList = () => {
  return request('/member/address', 'get')
}
/**
 * 删除收货地址
 * @param {object} address
 */
export const deleteAddress = (addressId) => {
  return request(`/member/address/${addressId}`, 'delete')
}
/**
 * 设置默认收货地址
 * @param {object} address
 */
export const setdefaultAddress = (addressId, isDefault) => {
  return request(`/member/address/${addressId}`, 'put', { isDefault })
}
/**
 * 提交订单
 * @param {object} order 订单信息对象
 */
export const createOrder = (order) => {
  return request('/member/order', 'post', order)
}
/**
 * 获取订单详情
 * @param {String} orderId 订单id
 */
export const findOrderDetail = (orderId) => {
  return request(`/member/order/${orderId}`, 'get')
}
/**
 * 获取我的订单列表
 * @param {Number} orderState 订单状态， 1为待付款、2为待发货、3为待收货、4为待评价、5为已完成、6为已取消，未传该参数或0为全部
 * @param {Number} page 页码
 * @param {Number} pageSize 每页条数
 */
export const findOrderList = ({ orderState, page, pageSize }) => {
  return request('/member/order/', 'get', { orderState, page, pageSize })
}
/**
 * 取消订单
 * @param {String} orderId 订单id
 * @param {String} cancelReason 取消原因
 * @returns Promise
 */
export const cancelOrder = (orderId, cancelReason) => {
  return request(`/member/order/${orderId}/cancel`, 'put', { cancelReason })
}
/**
 * 删除订单
 * @param {Arrary<string>} ids 删除订单，id集合
 * @returns
 */
export const deleteOrder = (orderId) => {
  return request('/member/order', 'delete', { ids: [orderId] })
}
/**
 * 确认收货
 * @param {String} orderId 订单id
 * @returns
 */
export const confirmReceipt = (orderId) => {
  return request(`/member/order/${orderId}/receipt`, 'put')
}
/**
 * 查看物流
 * @param {String} orderId 订单id
 * @returns
 */
export const logisticsOrder = (orderId) => {
  return request(`/member/order/${orderId}/logistics`, 'get')
}
/**
 * 获取再次购买的订单结算信息
 * @param {String} orderId 订单id
 * @returns
 */
export const findOrderRepurchase = (orderId) => {
  return request(`/member/order/repurchase/${orderId}`, 'get')
}
